<?php

include_once 'modules/mail/models/Mail.php';
include_once 'modules/user/models/User.php';
include_once 'modules/content/models/Content.php';
require_once 'modules/list/models/List.php';

class question_IndexController extends Nine_Controller_Action
{
	public function indexAction()
	{
		/**
		 * Display tempalte
		 */
	    $this->view->headTitle('Questionnaire');
	    $this->view->menuId = 'questionnaire';
	    
	    /**
	     * Get post data
	     */
	    $data = $this->_getParam('data', false);
	    $error = array();    
//			echo "<pre>"; print_r($data);die;
		if (false != $data) {
//			if (null != $_SESSION['captcha'] && $_SESSION['captcha'] == strtoupper(@$data['captcha'])) {
				try {
						/**
				         * Get admin
				         */
				        $objUser = new Models_User();
				        $admin = $objUser->getByUserName('admin');
				        /**
				         * Send message
				         */
				        $objMail = new Models_Mail();
				        /**
				         * Send to admin
				         */
				        $objMail->sendHtmlMail('contact', $data, $admin['email'],null, $admin['email']);
				        
				        $this->session->contactMessage = array(
				                                               'success' => true,
				                                               'message' => Nine_Language::translate('Message is send successfully')
				                                           );
				        $this->_redirect($this->_getCallBackUrl());
					}
				catch (Exception $e) {
					 $this->session->contactMessage = array(
		                                               'success' => false,
		                                               'message' => Nine_Language::translate('Can NOT send this message. Please try again')
		                                           );
				}
//			}
//			else {
//				unset($_SESSION['captcha']);
//				$this->session->contactMessage = array(
//		                                               'success' => false,
//		                                               'message' => Nine_Language::translate('Code is not match. Please type again')
//		                                           );
//			}
			
		}

//		$this->view->contactMessage = $this->session->contactMessage;
		/**
		 * Setbanner
		 */
		$this->session->frontBanner = 'media/userfiles/images/banner7.jpg';
		
        /**
         * Assign to view
         */
        $this->view->randomNumber = rand(0, 1000000);
	    $this->view->data = $data;
//	    $this->view->questionMessage = $this->session->questionMessage;
        $this->session->questionMessage = null;
        $contact = $this->session->contactMessage;
	    $this->view->contactMessage = $contact;
	     $this->session->contactMessage = null;
	}
}